package com.xuecheng.content.api;

import com.xuecheng.base.execption.RestErrorResponse;
import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 课程计划编辑接口
 * @Author dingchunlin
 * @Date 2024/3/29 20:56
 * @Version 1.0.0
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachplanController {

    @Autowired
    TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        List<TeachplanDto> teachplanDtoList = teachplanService.getTreeNodes(courseId);
        return teachplanDtoList;
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{planId}")
    public void deletePlanById(@PathVariable Long planId){
        teachplanService.deletePlanById(planId);
    }

    @ApiOperation("课程计划向下移动")
    @PostMapping("/teachplan/movedown/{planId}")
    public void movedown(@PathVariable Long planId){
        teachplanService.movedown(planId);
    }

    @ApiOperation("课程计划向上移动")
    @PostMapping("/teachplan/moveup/{planId}")
    public void moveup(@PathVariable Long planId){
        teachplanService.moveup(planId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资解除绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void associationMedia(@PathVariable("teachPlanId")Long teachPlanId,@PathVariable("mediaId")String mediaId){
        teachplanService.associationMedia(teachPlanId,mediaId);
    }
}

